package router

import (
	"github.com/gin-contrib/cors"
	"github.com/gin-gonic/gin"
	"loginApp/internal/handler"
)

// New 初始化 Gin 引擎并注册路由
func New() *gin.Engine {
	gin.SetMode(gin.ReleaseMode)
	r := gin.Default()

	// CORS 配置
	r.Use(cors.New(cors.Config{
		AllowOrigins: []string{"*"},
		AllowMethods: []string{"POST", "OPTIONS", "GET"},
		AllowHeaders: []string{"Content-Type", "Authorization"},
	}))

	// 页面路由
	r.GET("/login", handler.GetLoginPage)

	// 认证相关
	r.POST("/login", handler.PostLogin)
	r.GET("/auth/check", handler.GetAuthCheck)

	return r
}
